<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_slider_website extends MY_Controller {

    function __construct() {
        parent::__construct();
        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");
        $this->mslider_images = new M_slider_images();
    }

    function index() {
        $data['title'] = 'Data Slider Image Website';
        $data['list'] = $this->mslider_images->get();
        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {
        $data['title'] = 'Tambah Slider Image Website';
        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->load->helper('file');
        $dt = $this->mslider_images->where("id_slider = '$id'")->get();
        unlink('./uploads/slider/' . $dt->image_slider);
        $this->mslider_images->delete($id);
        redirect('admin_slider_website');
    }

    function simpan() {
        $config['overwrite'] = false;
        $config['upload_path'] = './uploads/slider/';
        $config['allowed_types'] = 'jpg|png|gif';
        $config['max_size'] = '100000';
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $field = 'image_slider';

        if ($this->upload->do_upload($field)) {
            $uploaded = $this->upload->data();
            $file = $uploaded['file_name'];
            $data = array(
                'keterangan_slider' => $this->input->post('keterangan_slider'),
                'image_slider' => $file,
            );
            $this->mslider_images->insert($data);

            redirect("admin_slider_website");
        }
    }

}

?>
